package edu.nf.hotel.roominfodao.impl;

import edu.nf.hotel.roominfo.RoomInfo;
import edu.nf.hotel.roominfo.RoomPredInfo;
import edu.nf.hotel.roominfodao.RoomPredInfoDao;
import edu.nf.hotel.util.ConnUtils;
import org.nf.db.util.SqlExecutor;
import org.nf.db.util.result.BeanListHandler;

import java.util.List;

/**
 * @Date 2023-06-28
 * @Author 带土
 */
public class RoompredInfoDapImpl implements RoomPredInfoDao {

    @Override
    public void getAddRoomPredInfo(RoomPredInfo r) {
        SqlExecutor executor = new SqlExecutor(ConnUtils.getConnection());
        String sql = "insert into roompred_info(r_id,predetermine_date,checkout_time,numbers,u_name," +
                "room_card,telephone)values(?,?,?,?,?,?,?)";
        executor.executeUpdate(sql,r.getRid(),r.getPredetermineDate(),r.getCheckoutTime(),
                r.getNumBers(),r.getUname(),r.getRoomCard(),r.getTelephone());
    }

    @Override
    public void getDeleteRoomPredInfo(int rpId) {
        SqlExecutor executor = new SqlExecutor(ConnUtils.getConnection());
        String sql = "delete from roompred_info where rp_id = ?";
        executor.executeUpdate(sql,rpId);

    }

    @Override
    public void getUpdateRoomPredInfo(RoomPredInfo r) {
        SqlExecutor executor = new SqlExecutor(ConnUtils.getConnection());
        String sql = "update roompred_info set r_id=?,predetermine_date=?,checkout_time=?,numbers=?," +
                "u_name=?,room_card=?,telephone=? where rp_id=?";
        executor.executeUpdate(sql,r.getRid(),r.getPredetermineDate(),r.getCheckoutTime(),
                r.getNumBers(),r.getUname(), r.getRoomCard(),r.getTelephone(),r.getRpId());
    }

    @Override
    public List<RoomPredInfo> getAllRoomPredInfo() {
        SqlExecutor executor = new SqlExecutor(ConnUtils.getConnection());
        BeanListHandler<RoomPredInfo> handler = new BeanListHandler<>(RoomPredInfo.class);
        String sql = "select rp_id,r_id,predetermine_date,checkout_time,predatermine_time,numbers,u_name," +
                "room_card,telephone from roompred_info";
        List<RoomPredInfo> list = executor.executeQuery(sql, handler);
        list.forEach(roomPredInfo-> System.out.println(roomPredInfo.getUname()));
        return list;
    }
}
